<template>
	<view class="login-container">
		<!-- 头部品牌 -->
		<view class="header">
			<text class="brand-name">直求</text>
			<text class="brand-slogan">一站式招投标服务平台</text>
		</view>
		
		<!-- 登录表单 -->
		<view class="login-form-container">
			<view class="glass-effect">
				<text class="welcome-text">欢迎回来</text>
				
				<view class="form-item">
					<text class="form-label">账号(身份证号/企业统一社会信用编号)</text>
					<view class="input-container">
						<image class="input-icon" src="/static/icons/user.png"></image>
						<input class="form-input" type="text" v-model="loginForm.id_card" placeholder="请输入账号"/>
					</view>
				</view>
				
				<view class="form-item">
					<text class="form-label">密码</text>
					<view class="input-container">
						<image class="input-icon" src="/static/icons/lock.png"></image>
						<input class="form-input" type="password" v-model="loginForm.password" placeholder="请输入密码"/>
					</view>
				</view>
				
				<view class="form-options">
					<view class="remember-pwd">
						<checkbox :checked="loginForm.remember" @tap="loginForm.remember = !loginForm.remember" style="transform:scale(0.7)"/>
						<text>记住密码</text>
					</view>
					<text class="forget-pwd" @tap="goToForgetPassword">忘记密码?</text>
				</view>
				
				<button class="login-btn" @tap="handleLogin">登录</button>
				
				<view class="register-link">
					<text>还没有账号? </text>
					<text class="link-text" @tap="goToRegister">立即注册</text>
				</view>
			</view>
		</view>
		
		<!-- 底部 -->
		<view class="footer">
			<view class="footer-btn" @tap="goToHelp">
				<image class="footer-icon" src="/static/icons/help.png"></image>
				<text class="footer-text">帮助</text>
			</view>
			<view class="footer-btn" @tap="contactCustomerService">
				<image class="footer-icon" src="/static/icons/phone.png"></image>
				<text class="footer-text">客服</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				loginForm: {
					id_card: '',
					password: '',
					remember: false
				}
			}
		},
		methods: {
			handleLogin() {
				// 表单验证
				if (!this.loginForm.id_card) {
					uni.showToast({
						title: '请输入账号',
						icon: 'none'
					});
					return;
				}
				if (!this.loginForm.password) {
					uni.showToast({
						title: '请输入密码',
						icon: 'none'
					});
					return;
				}
			uni.request({
			    url: 'http://115.190.38.218/go/api/v1/auth/login',
			    method: 'POST',
			    header: {
			        'Content-Type': 'application/json'  // 明确指定JSON格式
			    },
			    data: JSON.stringify({  // 手动序列化为JSON字符串
			        idCard: this.loginForm.id_card,
			        password: this.loginForm.password
			    }),
			    success(res) {
			        console.log("登录成功！", res);
					if(res.data.token){
						uni.setStorageSync('token',res.data.token);  // 使用后端返回的真实token
						uni.setStorageSync("type",res.data.user_type) //登录类型
						uni.setStorageSync("info",res.data.info) //存储基本信息
						uni.switchTab({ url: '/pages/index/index' });
						
					}else{
						console.log("有错",res)
						uni.showToast({
							title:'账号/密码错误',
							icon:'error'
						})
					}
			        
			    },
			    fail(err) {
			        console.log("登录失败！", err);
					uni.showToast({
						title:err,
						icon:'error'
					})
			    }
			});
				
			},
			goToRegister() {
				uni.navigateTo({
					url: '/pages/register/register'
				});
			},
			goToForgetPassword() {
				uni.showToast({
					title: '忘记密码功能',
					icon: 'none'
				});
			},
			goToHelp() {
				uni.showToast({
					title: '帮助中心功能',
					icon: 'none'
				});
			},
			contactCustomerService() {
				uni.showToast({
					title: '客服功能',
					icon: 'none'
				});
			}
		}
	}
</script>

<style>
	.login-container {
		display: flex;
		flex-direction: column;
		height: 100vh;
		background-image: linear-gradient(to bottom right, #3b82f6, #8b5cf6);
	}
	
	.header {
		padding: 60rpx 40rpx 30rpx;
	}
	
	.brand-name {
		font-size: 60rpx;
		font-weight: bold;
		color: #ffffff;
	}
	
	.brand-slogan {
		font-size: 30rpx;
		color: rgba(255, 255, 255, 0.8);
	}
	
	.login-form-container {
		flex: 1;
		display: flex;
		flex-direction: column;
		justify-content: center;
		padding: 0 40rpx;
	}
	
	.glass-effect {
		backdrop-filter: blur(10px);
		background-color: rgba(255, 255, 255, 0.7);
		border: 1px solid rgba(255, 255, 255, 0.18);
		box-shadow: 0 8rpx 12rpx rgba(0, 0, 0, 0.05);
		border-radius: 24rpx;
		padding: 40rpx;
	}
	
	.welcome-text {
		font-size: 36rpx;
		font-weight: bold;
		color: #333;
		margin-bottom: 40rpx;
	}
	
	.form-item {
		margin-bottom: 30rpx;
	}
	
	.form-label {
		font-size: 28rpx;
		color: #333;
		margin-bottom: 10rpx;
		display: block;
	}
	
	.input-container {
		position: relative;
	}
	
	.input-icon {
		position: absolute;
		left: 20rpx;
		top: 50%;
		transform: translateY(-50%);
		width: 40rpx;
		height: 40rpx;
	}
	
	.form-input {
		background-color: rgba(255, 255, 255, 0.7);
		border: 1px solid #e0e0e0;
		border-radius: 12rpx;
		height: 90rpx;
		padding-left: 70rpx;
		font-size: 28rpx;
	}
	
	.form-options {
		display: flex;
		justify-content: space-between;
		align-items: center;
		font-size: 26rpx;
		margin-bottom: 30rpx;
	}
	
	.remember-pwd {
		display: flex;
		align-items: center;
		color: #333;
	}
	
	.forget-pwd {
		color: #3b82f6;
		font-weight: 500;
	}
	
	.login-btn {
		background-color: #3b82f6;
		color: #fff;
		height: 88rpx;
		border-radius: 12rpx;
		font-size: 32rpx;
		font-weight: 500;
		margin-bottom: 30rpx;
	}
	
	.register-link {
		text-align: center;
		font-size: 28rpx;
		color: #333;
	}
	
	.link-text {
		color: #3b82f6;
		font-weight: 500;
	}
	
	.footer {
		padding: 40rpx 0;
		display: flex;
		justify-content: center;
		gap: 60rpx;
	}
	
	.footer-btn {
		display: flex;
		flex-direction: column;
		align-items: center;
		color: rgba(255, 255, 255, 0.8);
	}
	
	.footer-icon {
		width: 44rpx;
		height: 44rpx;
		margin-bottom: 6rpx;
	}
	
	.footer-text {
		font-size: 24rpx;
	}
</style> 